package com.sudu.dao;


import com.sudu.domain.Cover;
import com.sudu.domain.Detail;
import com.sudu.domain.UserInfo;
import com.sudu.domain.Video;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface VideoDao {

    @Insert("insert into t_video(title ,create_time , create_by , path , tag , img) " +
            "values(#{title},#{createTime},#{createBy},#{path},#{tag},#{img})")
    int saveVideo (Video video) ;

    @Select("select * from t_video where create_by = #{uid} and is_delete = 1")
    List<Video> selectByUid(int uid) ;

    @Select("select vid , title , img , click , comment , path , create_by , create_time , tag  from t_video where vid = #{vid} and is_delete = 1")
    Detail selectByVid(int vid) ;

    @Select("select vid , title , img , click , comment from t_video where tag = #{tagId} and is_delete = 1 limit #{page},#{pageSize} ")
    List<Cover> selectByPage(int tagId , int page , int pageSize) ;

    @Select("select vid , title , img , click , comment from t_video where tag = #{tag} and is_delete = 1 limit #{size}")
    List<Cover> selectCoverByTag(int tag , int size) ;

    @Select("select create_by from t_video where vid = #{vid} and is_delete = 1")
    int selectUidByVid(int vid) ;

    @Select("select vid , title , img , click , comment from t_video where create_by = #{uid} and is_delete = 1")
    List<Cover> selectCoverByUid(int uid) ;

    @Select("select vid , title , img , click , comment from t_video where vid = #{vid} and tag = #{tagId} and is_delete = 1 limit #{page},#{pageSize}")
    Cover selectCoverByVid(int vid , int tagId , int page , int pageSize) ;

    @Select("select vid , title , img , click , comment from t_video where create_by = #{uid} and tag = #{tagId} and is_delete = 1  limit #{page},#{pageSize}")
    List<Cover> getCoverByUid(int uid , int tagId , int page , int pageSize) ;

    @Select("select tag from t_video where vid = #{vid} and is_delete = 1  ")
    int getTagIdByVid(int vid) ;

    @Select("select tag from t_video where create_by = #{uid}  ")
    int[] getTagIdByUid(int uid) ;

    @Update("update t_video set is_delete = 0 where vid = #{vid}")
    int deleteByVid(int vid) ;

    @Update("update t_video set click = click+1 where vid = #{vid} and  is_delete = 1")
    int click(int vid) ;

    @Update("update t_video set comment = comment + 1 where vid = #{vid} and  is_delete = 1")
    int comment (int vid) ;

    @Select("select vid , title , img , click , comment from t_video where title like #{content} and tag = #{tagId} and is_delete = 1 limit #{page},#{pageSize}")
    List<Cover> search ( String content , int tagId , int page , int pageSize ) ;

    @Select("select vid from t_video where title like #{content} and is_delete = 1")
    int[] searchVidByContent(String content) ;

    @Update("update t_video set comment = comment - 1 where vid = #{vid} and  is_delete = 1")
    int delCom(int vid) ;
}
